home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / src / amiga.c.bak < prev    next >
Text File  |  1997-12-26  |  38KB  |  1,314 lines

  1. /*
  2.  * Vogle driver for the Amiga
  3.  *
  4.  * Written By: Dr. Charles E. Campbell, Jr.
  5.  * Version   : 1.00
  6.  * Date      : September 28, 1993
  7.  *
  8.  */
  9. #include <stdio.h>
  10. // #include <fcntl.h>
  11. #include <errno.h>
  12. #include <stdlib.h>
  13. #include <ctype.h>
  14.  
  15. #include <functions.h>
  16. #include <exec/types.h>
  17. #include <intuition/intuition.h>
  18. #include <libraries/dos.h>
  19. #include <graphics/rastport.h>
  20. #include <graphics/gfxmacros.h>
  21. #include <graphics/text.h>
  22. #include <exec/memory.h>
  23. #include <devices/inputevent.h>
  24. #include <clib/exec_protos.h>
  25. #include <clib/intuition_protos.h>
  26. #include <clib/console_protos.h>
  27.  
  28. #include "vogl.h"
  29.  
  30. #define INTUITION_REV    ((unsigned long) 33L)
  31. #define GRAPICS_REV        ((unsigned long) 33L)
  32.  
  33. /* --------------------------------------------------------------------------
  34.  * Definitions Section:
  35.  */
  36. #define SNGLBUFMODE    0    /* default scrbufmode value                    */
  37. #define DBLBUFMODE    1    /* scrbufmode value                            */
  38. #define RAWKEYBUF    128    /* initial size of rawkey buffer conversion    */
  39. #define KEYBUF        256    /* max size of keybuffer to be read            */
  40.  
  41. #define FONTSEP        ';'
  42. #define MAXVRTX        200
  43. #define MAXSTRING    1024
  44.  
  45. #ifdef SASC
  46. #define USESVMODE
  47. #endif
  48.  
  49. #ifdef AZTEC_C
  50. #define MEMTYPE    (MEMF_ANY|MEMF_CLEAR)
  51. #else
  52. #define MEMTYPE    (MEMF_ANY|MEMF_CLEAR)
  53. #endif
  54.  
  55. /* head_link: handles the generation of head-linked lists.  Note that 
  56.  *   each structure is assumed to have the member "nxt".
  57.  *   The new member becomes "head" - ie. oldest is last in the linked list,
  58.  *   the newest is first.
  59.  */
  60. #define head_link(structure,head,fail_msg) {         \
  61.     structure *newstr;                               \
  62.     newstr= (structure *) malloc(sizeof(structure)); \
  63.     if(!newstr) printf("***out of memory*** <%s>\n",fail_msg);   \
  64.     newstr->nxt= head;                               \
  65.     head    = newstr;                                \
  66.     }
  67.  
  68. /* stralloc: allocates new memory for and copies a string into the new mem */
  69. #define stralloc(ptr,string,fail_msg) {                             \
  70.     ptr= (char *) calloc((size_t) strlen(string) + 1,sizeof(char)); \
  71.     if(!ptr) printf("***out of memory*** <%s>\n",fail_msg);                  \
  72.     strcpy(ptr,string);                                             \
  73.     }
  74.  
  75. /* --------------------------------------------------------------------------
  76.  * Typedefs:
  77.  */
  78. typedef struct FontList_str FontList;
  79.  
  80. /* --------------------------------------------------------------------------
  81.  * Data Structures:
  82.  */
  83. struct FontList_str {
  84.     char            *fontspec;
  85.     struct TextFont *textfont;
  86.     FontList        *nxt;
  87.     };
  88.  
  89. /* --------------------------------------------------------------------------
  90.  * Extern Data:
  91.  */
  92. #ifdef AZTEC_C
  93. extern int Enable_Abort;
  94. #else
  95. void __regargs __checkabort (void);
  96. #endif
  97.  
  98. /* --------------------------------------------------------------------------
  99.  * Local Data:
  100.  */
  101. WORD                 *voglareaBuffer= NULL;
  102. struct BitMap        *voglback      = NULL;
  103. struct BitMap        *voglfront     = NULL;
  104. struct DiskFontBase  *DiskfontBase  = NULL;
  105. struct GfxBase       *GfxBase       = NULL;
  106. struct IntuiText     *voglitext     = NULL;
  107. struct IntuitionBase *IntuitionBase = NULL;
  108. struct IOStdReq      *vogl_cd_ioreq = NULL;
  109. struct Library       *ConsoleDevice = NULL;
  110. struct RastPort      *voglrastport  = NULL;
  111. struct Screen        *voglscreen    = NULL;
  112. struct TextAttr      *vogltextattr  = NULL;
  113. struct TmpRas        *vogltmpras    = NULL;
  114. struct Window        *voglwindow    = NULL;
  115.  
  116. static char               useborder       = 0;
  117. static char               scrbufmode      = SNGLBUFMODE;
  118. static char              *rawkeybuf       = NULL;
  119. static int                grfxmode        = 0;
  120. static int                currcolor       = 0;
  121. static UBYTE             *voglstring      = NULL;
  122. static UWORD              scrdepth        = 4;
  123. static UWORD              scrwidth        = 0;
  124. static UWORD              scrheight       = 0;
  125. static UWORD              voglscrbordleft = 0;
  126. static UWORD              voglscrbordright= 0;
  127. static UWORD              voglscrbordtop  = 0;
  128. static UWORD              voglscrbordbttm = 0;
  129. static USHORT             screenviewmode  = HIRES|LACE;
  130. static LONG               qtyrawkeybuf    = 0L;
  131. static FontList          *fontlisthd      = NULL;
  132. static struct InputEvent *voglievent      = NULL;
  133. static PLANEPTR          voglplaneptr     = NULL;
  134.  
  135. /* voglkeybuf
  136.  *   |uuuddddddduuuuu|    u=unused  d=data
  137.  *      ^       ^
  138.  *   ikeybgn    ikeyend   (always point to unused)
  139.  */
  140. static char     voglkeybuf[KEYBUF];
  141. static unsigned ikeyend= 0;            /* points just-past chars in voglkeybuf        */
  142. static unsigned ikeybgn= KEYBUF-1;    /* points just-before chars in voglkeybuf    */
  143.  
  144.  
  145. /* --------------------------------------------------------------------------
  146.  * Local Prototypes:
  147.  */
  148. static int AMIGA_config(char *);                             /* amiga.c         */
  149. static int AMIGA_init(void);                                  /* amiga.c         */
  150. static struct BitMap *makeBitMap(void);                /* amiga.c         */
  151. static int freeBitMap(struct BitMap *);                      /* amiga.c         */
  152. static int AMIGA_exit(void);                                  /* amiga.c         */
  153. static int AMIGA_draw( int, int);                            /* amiga.c         */
  154. static int AMIGA_getkey(void);                                /* amiga.c         */
  155. static int AMIGA_checkkey(void);                              /* amiga.c         */
  156. static int AMIGA_locator( int *, int *);                      /* amiga.c         */
  157. static int AMIGA_clear(void);                                /* amiga.c         */
  158. static int AMIGA_color(int);                                 /* amiga.c         */
  159. static int AMIGA_mapcolor( int, int, int, int);              /* amiga.c         */
  160. static int AMIGA_font(char *);                                /* amiga.c         */
  161. static int AMIGA_char(char);                                 /* amiga.c         */
  162. static int AMIGA_string(char *);                             /* amiga.c         */
  163. static int AMIGA_fill( int, int[], int[]);                   /* amiga.c         */
  164. static int AMIGA_backbuffer(void);                            /* amiga.c         */
  165. static int AMIGA_swapbuffer(void);                            /* amiga.c         */
  166. static int AMIGA_frontbuffer(void);                          /* amiga.c         */
  167. void _AMIGA_devcpy(void);                              /* amiga.c         */
  168.  
  169.  
  170. /* --------------------------------------------------------------------------
  171.  * Device Entry
  172.  *    fontname;height[;{BEIPU}]
  173.  *   B == bold
  174.  *   E == extended
  175.  *   I == italic
  176.  *   P == plain (default)
  177.  *   U == underlined
  178.  */
  179. static DevEntry amigadev = {
  180.     "AMIGA",                /* name of device                                */
  181.     "topaz;9;P",            /* name of small "hardware" font                */
  182.     "topaz;11;P",        /* name of large "hardware" font                */
  183.     AMIGA_backbuffer,    /* initializes double buffering                    */
  184.     AMIGA_char,            /* prints a "hardware" character                */
  185.     AMIGA_checkkey,        /* check if keyboard key hit, return it            */
  186.     AMIGA_clear,            /* clears viewport to background                */
  187.     AMIGA_color,            /* change current color index                    */
  188.     AMIGA_draw,            /* draws line from current to (x,y)                */
  189.     AMIGA_exit,            /* cleans up and allows vogle to exit            */
  190.     AMIGA_fill,            /* does filled polygons                            */
  191.     AMIGA_font,            /* sets up a hardware font                        */
  192.     AMIGA_frontbuffer,    /* switches drawing into front buffer            */
  193.     AMIGA_getkey,        /* gets a char of input                            */
  194.     AMIGA_init,            /* enables graphics                                */
  195.     AMIGA_locator,        /* finds mouse position in vogle device coords    */
  196.     AMIGA_mapcolor,        /* changes color at index to given rgb value    */
  197.     AMIGA_string,        /* prints a string of hardware text                */
  198.     AMIGA_swapbuffer};    /* swaps front and back buffers                    */
  199.  
  200. /* ==========================================================================
  201.  * Source Code:
  202.  */
  203.  
  204. /* AMIGA_config: This function modifies what AMIGA_init does.  It allows the
  205.  * user to control the type of screen and bitmaps used.  Note that one may
  206.  * use extra half-brite mode, too.  I put in ham mode since I expect to
  207.  * attempt to do some shading someday.
  208.  *
  209.  * The AMIGA_init sets up a gimmezerozero window using a custom Screen and
  210.  * BitMap.
  211.  *
  212.  * The config string may include:
  213.  *